package com.orangelife.mobile.buyFresh.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;

import java.util.List;
import java.util.Map;

public class BuyFreshGridViewAdapter extends BaseAdapter {
	
	private Context context;
	private List<Map<String,Object>> list;
	private ViewHolder holder;
//	private Handler mHandler;
	/**选择*/
	private int positionSelect;
//	/**上一次的选择*/
//	private int positionLast;

	private boolean isRent;
	public BuyFreshGridViewAdapter(Context context,List<Map<String,Object>> list,int position,boolean isRent) {
		this.context = context;
		this.list = list;
		this.positionSelect = position;
		this.isRent = isRent;
//		this.mHandler = handler;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
//		this.position = position;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_gv_buy_fresh, null);
			holder.tvWeight = (TextView)convertView.findViewById(R.id.tvWeight);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Map<String, Object> map = (Map<String, Object>) list.get(position);
		if(isRent){
			holder.tvWeight.setText(map.get("price").toString()+"元/天");
		}else {
			holder.tvWeight.setText(map.get("pdtDesc").toString());
		}
//		holder.tvWeight.setOnClickListener(new listener(map));
		if(positionSelect == position){
			holder.tvWeight.setBackgroundResource(R.drawable.shape_edit_orange);
			holder.tvWeight.setTextColor(context.getResources().getColor(R.color.text_color_orange));
		}
		return convertView;
	}
	
//	class listener implements View.OnClickListener {
//
//		private Map<String, Object> clikmap = null;
//
//		public listener(Map<String, Object> map) {
//
//			this.clikmap = map;
//		}
//
//		@Override
//		public void onClick(View view) {
//			switch (view.getId()) {
//			case R.id.tvWeight:
//				if(position != positionLast){
//					holder.tvWeight.setBackgroundResource(R.drawable.shape_edit_orange);
//					holder.tvWeight.setTextColor(R.color.text_color_orange);
//					mHandler.obtainMessage(10000, position);
//				}
//				positionLast = position;
//				break;
//
//			default:
//				break;
//			}
//
//		}
//	}
	  class ViewHolder{
			/** 规格 */
			public TextView tvWeight;
		}

}
  
